{include file="public/toper" /}
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">线下会员卡</a>
        <a><cite>会员卡列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <input type="text" name="sreach" value=""  style="width:250px;" id="key"   placeholder="店面人员/会员卡名称/单号" autocomplete="off" class="layui-input">
            <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <xblock class="demoTable">
        <button class="layui-btn" onclick="x_admin_show('添加线下会员卡代售','{:url(\'Offline/add\')}','800','580')"><i class="layui-icon"></i>添加</button>
    </xblock>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="image">
    <img src="{{d.qrcode}}" class="thumb" thumb="{{ d.qrcode }}"/>
</script>
<script type="text/html" id="action">
    <button class="layui-btn-danger layui-btn layui-btn-xs del_btn" id="{{d.offline_id}}" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</button>
</script>
<script>
    layui.use(['table','util','layer'], function(){
        var table = layui.table, $ = layui.jquery;
        var layer = layui.layer;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Offline/index')}"
            ,id:'test'
            ,cols: [[
                {field:'offline_id', width:80, title: '序号',align: 'center',type:'numbers'}
                ,{field:'sname',width:130, title: '销售人员',align: 'center'}
                ,{title: '二维码',width:100,templet: '#image',align: 'center'}
                ,{field:'cname',width:180, title: '会员卡名称',align: 'center'}
                ,{field:'sales_order',width: 150,title: '销售单号', align: 'center'}
                ,{field:'price',width: 100,title: '价格', align: 'center'}
                ,{field:'effective',width:100, title: '有效期',align: 'center'}
                ,{field:'create_time', width:180, title: '生成时间',align: 'center',templet: '<div>{{layui.util.toDateString(d.create_time*1000)}}</div>'}
                ,{width:100, title: '绑定人',align: 'center',templet:function(d){ return d.card.name;}}
                ,{width:130, title: '绑定时间',align: 'center',templet:function(d){ return d.card.purchase_time; }}
                ,{width:130, title: '开始时间',align: 'center',templet:function(d){ return d.card.start_time; }}
                ,{width:130, title: '结束时间',align: 'center',templet:function(d){ return d.card.validity_time; }}
                ,{width:100,title: '操作', align: 'center', toolbar: '#action'}
            ]]
            ,page:true
        });
        layer.close(loading);

        $('#search').on('click', function () {
            tableIn.reload({
                where: {key: $('#key').val()}
                ,page: {curr: 1 }
            });
        });

        table.on('tool(test)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除【'+data.cname+'】吗？',{btnAlign: 'c'}, function(index){
                    var loading = layer.load(1, {shade: [0.1,'#fff'] });
                    $.post("{:url('Offline/del')}",{id:data.offline_id},function(res){
                        layer.close(loading);
                        if(res.code==200){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload(test)
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

    });
</script>
{include file="public/footer"/}